﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Assets.Scripts.TDuResource
{
    struct SceneAttr
    {
        public int nTimes;
        public int nFPS;
        public int nLimitErrorCount;
        public double fScores;
        public bool bLoopByName;
        public string strNavagation;
        public string strBgSound;
    }
    struct SceneSteps
    {
        public string strBigStep;
        public List<string> arrSmlSteps;
    }
    enum PracticeMode
    {
        E_STUDY = 0,
        E_PRACTICE,
        E_EXAM,
    };
    enum SceneType
    {
        E_QUESTION = 0,
        E_SHOW,
        E_ASSEMBLE,
        E_DISMANTLE,
        E_SIMULATION,
        E_INTELLIGENT,
    };
    struct Property
    {
        public string strNavagation;
        public string strSkyBox;
        public string strInfoCap;
        public string strAssistPic;
        public float fAniSpeed;
        public float fWalkSpeed;
        public float[] arrBackGround;

        public bool bAnimationState;
        public bool bMultiViews;
        public bool bCaption;
        public bool bSound;
        public bool bBgColor;
        public bool bShowVP;
        public bool bFindView;
        public bool bHavePic;
        public bool bAllowThrow;
        public bool bHaveRota;
        public bool bToolAutoBack;

        public int nHintPos;
        public int nBigPos;
        public int nSmallPos;

        public int[] arrObjRGBA;

        public PracticeMode ePracticeMode;
        public SceneType eSceneType;
        public string transparentObj;
    };

    //-----------------------------------ProjectConfig Define Start-----------------------------------/
    //对应配置文件中的ProjectConfig节点
    struct ProjectConfig
    {
        public string strProjectName;
        public string strBGPicturePath;
        public string strSchoolName;
        public string strCollegeName;
        public string strCourseName;
        public string strProfessionCode;
        public string strProfessionName;
        public string strPrincipalName;
        public string strProjectMembers;
        public string strProjectDetail;
    }
    //-----------------------------------ProjectConfig Define End-------------------------------------/

    //-----------------------------------TDuWebXR Define Start-----------------------------------/
    struct TDuWebVRConfig
    {
        public HashSet<string> vecFloorsName;
        public double[] vecScalingFactors;
        public string strDashboardName;
        public int nDashboardSize;
        public bool bUseMainButtonToTeleportate;
        public int ntimeToTeleportate;
    }
    //-----------------------------------TDuWebXR Define End-------------------------------------/

    //-----------------------------------MusicOfficeInfo Define Start-----------------------------------/
    struct Absorption
    {
        public string strFrequency;
        public double dAbsorptionCoefficient;
    }
    //-----------------------------------MusicOfficeInfo Define End-----------------------------------/

    //对应配置文件中的MaterialInfo节点(音乐厅项目中需要使用到的材质列表)
    struct Material
    {
        public string strMaterialName;
        public int dMaterialArea;
        public string strMaterialID;
        public List<Absorption> vecAbsorptions;
    }

    struct humidityAbsorption
    {
        public string strHumidity;
        public double dHumidityAbsorption;
    }

    struct AirAbsorptions
    {
        public string strFrequency;
        public List<humidityAbsorption> vecHumidityAbsorptions;
    }

    struct MaterialReplacedRecord
    {
        public string strMeshName;
        public string strReplacedImage;
    }

    struct AnimationExecutedRecord
    {
        public string strStepName;
        public string strActivateObj;
    }

    struct MusicOfficeInfo
    {
        public double dReverbTime;
        public double dVolume;
        public List<AirAbsorptions> airAbsorptions;
        public List<Material> vecMaterials;
        public List<MaterialReplacedRecord> vecReplacedMaterial;
        public List<AnimationExecutedRecord> vecExecutedAnimation;
    }
    //-----------------------------------MusicOfficeInfo Define End-------------------------------------/

    //-----------------------------------SceneEnvironment Define Start---------------------------------------
    //对应配置文件中得Environment节点;
    struct SceneEnvironment
    {
        public string strSkyTexture;
        public string strEnvTexture;
        public double[] arrGroundColor;
        public bool bUseSkybox;
        public bool bUseGround;
        public bool bUse;
    }
    //-----------------------------------SceneEnvironment Define End------------------------------------------/

    //-----------------------------------SceneNode Define Start---------------------------------------
    //对应配置文件中的基本里面的<Node>
    struct SceneNode
    {
        public string strName;
        public string strFile;
        public string strUserID;
        public string strModelID;

        public bool bDynamic;
        public bool bUsingShadow;

        public double nLevel;
        public double[] vec3Pos;
        public double[] vec3Size;
        public double[] vec3Rota;
        public double[] vec3Scale;
    }
    //-----------------------------------SceneNode Define End------------------------------------------/

    //-----------------------------------SceneSwitch Define Start-------------------------------------
    //对应配置文件中的基本里面的视图<Switch>
    struct SwitchCase
    {
        public string strCaseName;
        public List<string> arrNodeName;
    }

    struct SceneSwitch
    {
        public int nChoice;
        public List<SwitchCase> arrCases;
    }
    //------------------------------------SceneSwitch Define End--------------------------------------/

    //-----------------------------------ViewPort Define Start----------------------------------------
    //对应配置文件中的视点<Viewport>
    struct ViewPort
    {
        public string strViewPortName;
        public bool bSlave;
        public bool bFolder;
        public float[] arr3Pos;
        public float[] arr3Rota;
        public List<ViewPort> vecItems;
    }
    //-----------------------------------ViewPort Define End------------------------------------------/

    //-----------------------------------ExplosiveView Define Start-----------------------------------
    //对应配置文件中的爆炸图<ExplosiveView>
    struct ExplosiveView
    {
        public string strExplosiveViewName;
        public string strFileName;
        public string strUserID;
        public string strSceneID;
        public bool bUseUI;
    }
    //-----------------------------------ExplosiveView Define End-------------------------------------/

    //-----------------------------------BipAnimation Define Start-----------------------------------
    struct BipAnimation
    {
        public string strBipName;
        public string strBipChild;
    }
    //-----------------------------------BipAnimation Define End-----------------------------------

    //-----------------------------------ToolsTranslate Define Start-----------------------------------
    struct ToolsTranslate
    {
        public string strToolImage;
        public string strToolChineseName;
        public string strToolEnglishName;
    }
    //-----------------------------------ToolsTranslate Define End-----------------------------------

    //-----------------------------------VariableState Define Start-------------------------------------/
    struct VariableState
    {
        public string strDisp;
        public string strType;
        public string strFactorName;
        public List<ConditionState> arrPreState;
        public List<ConditionState> arrCondition;
        public List<ConditionState> arrAction;
        public List<VariableState> vecItems;
        public double dFactor;
        public bool bFolder;
    }
    //-----------------------------------VariableState Define End-------------------------------------/

    //-----------------------------------SchematicView Define Start-----------------------------------
    //对应配置文件中的原理图<SchematicView>
    struct SchematicView
    {
        public string strSchematicView;
        public string strFileName;
        public string strUserID;
        public string strSceneID;
        public bool bUseUI;
    }
    //-----------------------------------SchematicView Define End-----------------------------------/

    //-----------------------------------ConditionValue Define Start-----------------------------------
    public enum ValueType
    {
        E_Value = 0,
        E_Alias = 1,
    }

    //对应配置文件的变量的条件值
    public class ConditionValue
    {
        public string strAlias;
        public double dValue;
        public ValueType eValueType;


        public ConditionValue(double dvalue, string strValue)
        {
            if (strValue != "")
            {
                if (strValue.Substring(0, 1) == "$")
                {
                    this.eValueType = ValueType.E_Alias;
                    this.dValue = 0;
                    this.strAlias = strValue.Substring(1, strValue.Length - 1);
                }
                else
                {
                    this.dValue = float.Parse(strValue);// Convert.ToInt32(strValue, 10);// parseInt(strValue, 10);
                    this.eValueType = ValueType.E_Alias;
                    this.strAlias = "";
                }
            }
            else
            {
                this.eValueType = ValueType.E_Value;
                this.dValue = dvalue;
                this.strAlias = "";
            }
        }
        public string getValueStr()
        {
            string strRet = "";
            if (this.eValueType == ValueType.E_Alias)
            {
                strRet = "$" + this.strAlias;
            }
            else
            {
                strRet = this.dValue.ToString();// Convert.ToString(this.dValue);//.toString();
            }

            return "";
        }

        public double value(Dictionary<string, VariableNode> mapVars)
        {
            double dRet = this.dValue;

            if (this.eValueType == ValueType.E_Alias)
            {
                if (this.strAlias != "")
                {
                    int nPos = this.strAlias.IndexOf('$');
                    if (nPos == -1)
                    {
                        foreach (var key in mapVars.Values)
                        {
                            if (key.strVarNodeName == this.strAlias)
                            {
                                dRet = key.dVarCurValue;
                            }
                        }

                        return dRet;
                    }

                    // 处理”$变量名$*$@10$+$变量名”形式
                    string wstr = this.strAlias;
                    string c = "+";
                    while (wstr.Length > 0)
                    {
                        string str = wstr;
                        if (nPos != -1)
                        {
                            str = wstr.Substring(0, nPos);
                            wstr = wstr.Substring(nPos + 1, wstr.Length - nPos - 1);
                            nPos = wstr.IndexOf('$');
                        }
                        else
                        {
                            wstr = "";
                        }

                        if (str.Length > 1)
                        {
                            double myValue = 0;
                            if (str[0] == '@')
                            {
                                myValue = int.Parse(str.Substring(1, str.Length - 1)); //Convert.ToInt32(str.Substring(1, str.Length - 1));
                            }
                            else
                            {
                                foreach (var key in mapVars.Values)
                                {
                                    if (key.strVarNodeName == str)
                                    {
                                        myValue = key.dVarCurValue;
                                    }
                                }
                            }
                            switch (c)
                            {
                                case "+": dRet += myValue * 1; break;
                                case "-": dRet -= myValue * 1; break;
                                case "*": dRet *= myValue * 1; break;
                                case "/": if (myValue != 0) { dRet /= myValue; dRet = dRet * 1; } break;
                                case "%": if (myValue != 0) { dRet = 1 * dRet % 1 * myValue; } break;
                                default: dRet += myValue; break;
                            }
                        }
                        else { c = str[0].ToString(); /*Convert.ToString(str[0]);*/ }
                    }
                }

            }
            return dRet;
        }
    }
    //-----------------------------------ConditionValue Define Start----------------------------------/

    //-----------------------------------ConditionState Define Start----------------------------------
    //比较类型;
    public enum EqualType
    {
        Greater = 0,
        GreaterEqual,
        Less,
        LessEqual,
        Equal,
        NotEqual
    }
    //逻辑操作类型
    public enum LogicType
    {
        And = 0,
        Or,
        Add,
        Sub
    }

    //对应配置文件的变量的条件状态
    public class ConditionState
    {
        public string strName;
        public bool bJump;
        public bool bSync;
        public int nLeavel;
        public ConditionValue cDestValue;
        public ConditionValue cNotValue;
        public ConditionValue cStepValue;
        public ConditionValue cTime;
        public ConditionValue cNotTime;
        public EqualType eEqualType;
        public LogicType eLogicType;
        public ConditionState()
        {
            this.strName = "";
            this.bJump = false;
            this.bSync = false;
            this.nLeavel = 0;
            this.eEqualType = EqualType.Equal;
            this.eLogicType = LogicType.And;
            this.cDestValue = new ConditionValue(0.0, "");
            this.cNotValue = new ConditionValue(0.0, "");
            this.cStepValue = new ConditionValue(0.0, "");
            this.cTime = new ConditionValue(0.0, "");
            this.cNotTime = new ConditionValue(0.0, "");
        }
    }
    //-----------------------------------ConditionState Define End----------------------------------/

    //-----------------------------------InitVarState Define Start----------------------------------/
    //对应配置文件中的InitVarState节点
    struct InitVarState
    {
        public string strName;
        public double dInitValue;
        public double dDescValue;
        public double dScore;
        public double dDecution;
        public double nStandardCount;
        public bool bDisableUpdate;
        public bool bErrorStep;
    }

    struct FullInitVarState
    {
        public string strDescription;
        public string strSubject;
        public List<InitVarState> arrVarStates;
    }
    //-----------------------------------InitVarState Define End------------------------------------/

    //-----------------------------------VariableNode Define Start------------------------------------
    //对应配置文件中的变量<VariableNode>
    public class VariableNode
    {
        public string strVarNodeName;
        public string strVarNodeType;
        public string strVarStepDisp;//没用到
        public string strVarAudio;//声音
        public string strVarTools;//工具
        public string strVarPictureType;//图片类型
        public string strVarPicturePath;//图片路径
        public string strVarWarning;//没用到
        public string strVarText;//提示文字
        public string strVarViewport;//视点
        public bool bVarRandom; //取值随机
        public bool bVarLoop;//动画循环还是步骤循环？
        public bool bVarAssess;//考核显示
        public bool bComplete;//包括  啥意思？
        public bool bFolder;//
        public double dVarStartTime;
        public double dVarStopTime;
        public double dVarMinValue;
        public double dVarMaxValue;
        public double dVarCurValue;
        public double dVarStep;
        public double nCurCount;
        public HashSet<string> setActiveObj;//激活物体
        public string strAnimateObj;
        public string[] setAnimateObj;
        public string[] arrOrder;
        public string[] arrAssemble;
        public List<int> arrPeople;
        public string[] arrErrorInfo;
        public List<ConditionState> arrPreCondtion;
        public List<ConditionState> arrCondition;
        public List<VariableNode> vecItems;

        public VariableNode()
        {
            this.strVarAudio = "";
            this.strVarNodeName = "";
            this.strVarNodeType = "";
            this.strVarPicturePath = "";
            this.strVarPictureType = "";
            this.strVarStepDisp = "";
            this.strVarText = "";
            this.strVarTools = "";
            this.strVarViewport = "";
            this.strVarWarning = "";
            this.strAnimateObj = "";

            this.bComplete = false;
            this.bVarAssess = false;
            this.bVarLoop = false;
            this.bVarRandom = false;
            this.bFolder = false;

            this.dVarCurValue = 0.0;
            this.dVarMaxValue = 0.0;
            this.dVarStartTime = 0.0;
            this.dVarStopTime = 0.0;
            this.dVarStep = -10.0;
            this.dVarMinValue = 0.0;
            this.nCurCount = 0;

            this.setActiveObj = new HashSet<string>();
            this.arrPeople = new List<int>();
            this.arrPreCondtion = new List<ConditionState>();
            this.arrCondition = new List<ConditionState>();
            this.vecItems = new List<VariableNode>();
        }

        public double fraction(double time)
        {
            double dStartTime = 0.0;

            this.dVarCurValue = time;

            if (this.dVarCurValue > this.dVarMaxValue)
                this.dVarCurValue = this.dVarMaxValue;
            if (this.dVarCurValue < this.dVarMinValue)
                this.dVarCurValue = this.dVarMinValue;

            double dValeRange = this.dVarMaxValue - this.dVarMinValue;
            double dAniRang = this.dVarStopTime - this.dVarStartTime;
            dStartTime = this.dVarStartTime + dValeRange * (this.dVarCurValue - this.dVarMinValue) / dValeRange;

            return this.dVarStartTime;
        }

        public double scroll(double dScrollValue)
        {
            if (this.strVarNodeType == "Click")
            {
                if (this.dVarCurValue >= (this.dVarMaxValue - 0.01))
                {
                    this.dVarCurValue = this.dVarMinValue;
                    return this.dVarStartTime;
                }
                else
                {
                    this.dVarCurValue = this.dVarMaxValue;
                    return this.dVarStopTime;
                }
            }
            else
            {
                double dValueRange = this.dVarMaxValue - this.dVarMinValue;
                if (this.dVarStep > 0.0)
                    this.dVarCurValue = this.dVarCurValue + this.dVarStep * dScrollValue;
                else
                    this.dVarCurValue = this.dVarCurValue + dValueRange * dScrollValue / 36;

                if (this.dVarCurValue > this.dVarMaxValue)
                    this.dVarCurValue = this.dVarMaxValue;
                if (this.dVarCurValue < this.dVarMinValue)
                    this.dVarCurValue = this.dVarMinValue;

                double dAniRang = this.dVarStopTime - this.dVarStartTime;
                double dStartTime = this.dVarStartTime + dAniRang * (this.dVarCurValue - this.dVarMinValue) / dValueRange;
                return dStartTime;
            }
        }

        public double getCurValueTime()
        {
            double dStartTime = 0.0;
            double dValueRange = this.dVarMaxValue - this.dVarMinValue;
            if (this.dVarCurValue > this.dVarMaxValue)
                this.dVarCurValue = this.dVarMaxValue;
            if (this.dVarCurValue < this.dVarMinValue)
                this.dVarCurValue = this.dVarMinValue;

            double dAniRang = this.dVarStopTime - this.dVarStartTime;
            dStartTime = this.dVarStartTime + dAniRang * (this.dVarCurValue - this.dVarMinValue) / dValueRange;
            return dStartTime;
        }
    }
}

//-----------------------------------Sprites Define Start---------------------------------------
//对应配置文件中得Sprites节点;
struct SceneSprite
{
    public string strSpriteName;
    public string strImgUrl;
    public double nImgWidth;
    public double nImgHeight;
    public double nSpriteWidth;
    public double nSpriteHeight;
    public double nPlantDistance;
    public double nPlantNumber;
    public string strReferenceMesh;
}
//-----------------------------------Sprites Define End------------------------------------------/

//-----------------------------------Sprites Define End------------------------------------------/
struct ScenePhotoDome
{
    public string strImg;
}
//-----------------------------------SceneSteps Define Stop---------------------------------------/

//-----------------------------------VariableNode Define End-------------------------------------/

//-----------------------------------TDuTimer Define Start---------------------------------------/

//-----------------------------------TDuTimer Define End-----------------------------------------/
